<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Wechatdone extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
    function __construct()
    {
        parent::__construct();
        $this->load->library('CI_Wechat');
        $this->load->helper('url');
        //$this->ci_wechat->valid();
    }

    public function createMenu(){
    	$wechat_domain=$this->config->item('wechat_domain');
    	var_dump($wechat_domain);
    	$data=array (
    			'button' => array (
    					0 => array (
    							'name' => '我要问政',
    							'type' => 'view',
    							'sub_button' => array (
    									0 => array (
    											'type' => 'view',
    											'name' => '提交问政',
    											'url'=> $wechat_domain.'/wechat/messages'
    									)
    							)
    					),
    					1 => array (
    							'name' => '问政信息',
    							'type' => 'view',
    							'sub_button' => array (
    									0 => array (
    											'type' => 'view',
    											'name' => '最新爆料',
    											'url' => $wechat_domain.'/wechat/messages/newest',
    									),
    									1 => array (
    											'type' => 'view',
    											'name' => '最新回复',
    											'url' => $wechat_domain.'/wechat/messages/reply',
    									),
    									2 => array (
    											'type' => 'view',
    											'name' => '问政查找',
    											'url' => $wechat_domain.'/wechat/messages/query',
    									)
    							)
    					),
    					2 => array (
    							'name' => '我',
    							'type' => 'view',
    							'sub_button' => array (
    									0 => array (
    											'type' => 'view',
    											'name' => '个人信息',
    											'url' => $wechat_domain.'/wechat/users'
    									)
    							)
    					)
    			)
    	);
    	$result=$this->ci_wechat->createMenu($data);
    	var_dump($result);
    }
    public function getMenu(){
    	$result=$this->ci_wechat->getMenu();
    	echo "<pre>";
    	var_dump($result);
    }
    

   /**********************************************************************************************/
    //消息情况处理
    public function donemsg(){
    	$this->ci_wechat->valid();
    	$type = $this->ci_wechat->getRev()->getRevType();
    	switch($type) {
    		case Wechat::MSGTYPE_EVENT:
    			$datamsg="欢迎使用立普威陆车载WIFI";
    			$event_arr= $this->ci_wechat->getRevEvent();
    			if(isset($event_arr['event'])&&$event_arr['event']==Wechat::EVENT_SUBSCRIBE){//订阅时发送欢迎消息
    				$FromUserName=$this->ci_wechat->getRevFrom();//得到消息发送者
    				$data="$datamsg";
    				$this->ci_wechat->text("$data")->reply();
    			}
    			break;
    		case Wechat::MSGTYPE_IMAGE:
    			break;
    		default:
    			$datamsg="欢迎使用立普威陆车载WIFI";
    			$this->ci_wechat->text("$datamsg")->reply();
    	}
    }
}
